import QtQuick 1.0
import Kookaburra 1.0

Rectangle {
    // Movement properties
    property bool moving   : true
    property int direction : 1
    property int speed     : 3
    property int moveCount      : 0


    // Attacking properties
    property int attackDelay: 30
    property bool attacking : false
    property int attackCount: 0
    property bool dead : false;

    // Stats
    property int strength   :  15
    property int defense    :  7
    property int health     :  45

    property string level: ""

    property bool paused: true

    id: boss


    onDeadChanged: {
        if (dead) {
            boss.visible = false;

        }
    }

    width: 70
    height: 100

    color: "black"



    function updatePositionX(amount) {
        if(boss.x + amount < 0) {
            boss.x = 0;
        } else if (boss.x + amount > map.width) {
            boss.x = map.width;
        } else {
            boss.x += amount;
        }
    }

    CollisionRectangle {
        solid: false
        debug: false

        objectName: "boss"

        //should be able to use anchors here!
        width: parent.width
        height: parent.height
    }

    /* Movement timer */
    Timer {
        id: movementTimer
        interval: 50
        repeat: true
        running: !paused

        onTriggered: {
            if(player.x + player.width - 1 < boss.x) {
                direction = -1

                if(attackCount == 0) {
                    attacking = !attacking;
                }

                attackCount = (attackCount + 1) % (attackDelay + 1);

            } else if(player.x > boss.x + boss.width)
                {
                direction = 1;


                if(attackCount == 0) {
                    attacking = !attacking;
                }

                attackCount = (attackCount + 1) % (attackDelay + 1);

            }else {
                direction = 0;
            }

            updatePositionX(boss.direction * boss.speed)
        }
    }

}
